package cn.lin.controller;

import cn.lin.util.OSSUtil;
import cn.lin.util.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author qmp
 * @date 2024/12/4 23:58
 */
@RestController
@RequestMapping("/upload")
public class ImageController {

    @RequestMapping("/image")
    public Object uploadImg(@RequestParam("file")MultipartFile file){
        try {
            String url = OSSUtil.upload(file.getOriginalFilename(), file.getInputStream());
            return Result.ok("上传成功",url) ;
        } catch (IOException e) {
            return Result.error("上传失败") ;
        }
    }

}
